// $Id: randomize.c,v 1.1 2006-09-11 07:42:28 nicolasw Exp $

#include <stdio.h>		// para fopen(), etc
#include <stdlib.h>		// para srand()

#include "randomize.h"

// Mirar lo que pasa si se usa /dev/random
#define RANDOM_DEV "/dev/urandom"
#define DEFAULT_SEED 1 

void 
randomize(void) {
	FILE *fd = NULL;
	unsigned int read = 0;
	unsigned int buffer = 0;

	fd = fopen(RANDOM_DEV, "r");
	if (fd==NULL) {
		perror("randomize: error opening RANDOM_DEV");
		srand(DEFAULT_SEED);
	} else {
		read = fread((void *)&buffer, sizeof(unsigned int), 1, fd);
		if (read != 1) {
			perror("randomize: error reading RANDOM_DEV");
			srand(DEFAULT_SEED);
		} else {
			srand(buffer);
			fclose(fd);
		}
	}
}
